package com.vend.shop.view

import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebView
import androidx.annotation.RequiresApi
import com.alibaba.android.arouter.facade.annotation.Route
import com.vend.common.base.BaseWebFragment
import com.vend.common.base.model.FragmentType
import com.vend.common.constant.RouterConstant
import com.vend.common.mvp.IView
import com.vend.shop.R
import com.vend.shop.presenter.ShopFragmentPresenter
import kotlinx.android.synthetic.main.fragment_shop_list.*

/**
 * Created by glendal on 2022/01/25.
 * 购物车Fragemnt
 */
@Route(path = RouterConstant.SHOP_LIST_FRAGMENT)
class ShopListFragment : BaseWebFragment<ShopFragmentPresenter>(),ShopView {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mPresenter = ShopFragmentPresenter(mSelf,this,this.arguments)
        mPresenter?.initArgument()
        return super.onCreateView(inflater, container, savedInstanceState)
    }
    override fun initView(view: View, savedInstanceState: Bundle?) {

    }

    override fun onDestroyView() {
        mPresenter?.stop()
        super.onDestroyView()
    }

    override fun getContentViewId(): Int {
        return R.layout.fragment_shop_list
    }

    override fun lazyInit() {
        super.lazyInit()
        //这里将类型设置进去
        setFragmentType(FragmentType.Fragment_Shop.fType)
    }

    override fun getUrl(): String? {
        return "https://m.jd.com/"
    }
    override fun getAgentWebParent(): ViewGroup {
        return v_web_contain_shop
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun shouldLoadingUrl(view: WebView?, request: WebResourceRequest?): Boolean {
        val detailUrl = request?.url.toString()
        Log.e("tag", "url  $detailUrl")
        return false
    }

    override fun setViewPageStatue(statue: Boolean) {
        setViewPageFragment(statue)
    }
}
interface ShopView:IView{
    /**
     * 是否ViewPage+Fragment懒加载
     */
    fun setViewPageStatue(statue : Boolean)
}